<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
  <title>Redland librdf RDF API Library - Building and Installing from Source</title>
</head>
<body>

<h1>Redland librdf RDF API Library - Building and Installing from Source</h1>


<h2>1. Getting the sources</h2>

<p>There are several ways to get the sources.  The most stable and
tested versions are the sources shipped with each release and these
are recommended as the first place to start.  For the latest
developent sources, anonymous GIT access is available but this may
require some configuring of developer tools that are not needed for
the releases.</p>

<p>The source bundle and package files contain all the HTML files and
documentation provided on the web site.</p>

<p>Redland (librdf) requires the Raptor and Rasqal to be already
built and installed (libraries, headers and pkg-config .pc files).
See the
<a href="http://librdf.org/raptor/INSTALL.html">Raptor install document</a>
and
<a href="http://librdf.org/rasqal/INSTALL.html">Rasqal install document</a>
for the details of installing them.
</p>


<h3>1.1. Getting released sources</h3>

<p>Every release comes with full sources and these are available from
<a href="http://download.librdf.org/source/">http://download.librdf.org/source/</a>.
</p>


<h3>1.2. Getting the sources from GIT</h3>

<pre>
  git clone git://github.com/dajobe/librdf.git
  cd librdf
</pre>


<p>At this stage, or after a <code>git pull</code> you will
need to create the automake and autoconf derived files, as described
below in <a href="#sec-create-configure">Create the configure program</a>
by using the <code>autogen.sh</code> script.</p>

<p>Building Redland in this way requires some particular development
tools not needed when building from snapshot releases - automake,
autoconf, libtool and dependencies.
The <code>autogen.sh</code> script looks for the newest versions
of the auto* tools and checks that they meet the minimum versions.</p>



<h2>2. Configuring and building</h2>

<p>Redland uses the GNU automake and autoconf to handle system
dependency checking.  It is developed and built on x86 Linux
and x86 OSX but is also tested on other systems occasionally.
</p>


<p>configure tries very hard to find several programs and libraries
that Redland might need.  These include the storage modules
(Berkeley/Sleepycat DB, MySQL, PostgreSQL 3store) and various others.
A summary of the modular parts found is given at the end of the
configure run.  Several options to configure given below can be used
to point to locations or names of dependencies that cannot be
automatically determined.</p>


<h3><a id="sec-create-configure" name="sec-create-configure"></a>2.1. Create <code>configure</code> program</h3>

<p>If there is no <code>configure</code> program, you can create it 
by running the <code>autogen.sh</code> script, as long as you have the
<a href="http://www.gnu.org/software/automake/automake.html">automake</a> and
<a href="http://www.gnu.org/software/autoconf/autoconf.html">autoconf</a>
tools.  This is done by:</p>
<pre>
  ./autogen.sh
</pre>
<p>and you can also pass along arguments intended for configure (see
below for what these are):</p>
<pre>
  ./autogen.sh --prefix=/usr/local/somewhere
</pre>

<blockquote>
<p>On OSX you may have to explicitly set the <code>LIBTOOLIZE</code>
variable for the <code>libtoolize</code> utility since on
OSX <code>libtoolize</code> is a different program.  The full
path to the utility should be given:</p>
<pre>
  LIBTOOLIZE=/opt/local/bin/glibtoolize ./autogen.sh
</pre>
</blockquote>

<p>Alternatively you can run the automake and autoconf programs by
hand with:</p>
<pre>
  aclocal; autoheader; automake --add-missing; autoconf
</pre>

<p>The automake and autoconf tools have many different versions and
<code>autogen.sh</code> enforces the minimums. At present development
is being done with automake 1.10.2 (minimum version 1.7), autoconf
2.63 (minimum version 2.54) and libtool 2.2.6 (minimum version 2.2.0).
These are only needed when compiling from GIT sources.
autogen.sh enforces the requirements.</p>


<h3>2.2. Options for <code>configure</code></h3>

<p>See also the generic GNU installation instructions in 
<a href="INSTALL">INSTALL</a> for information about general options
such as <code>--prefix</code> etc.</p>

<dl>
<dt><code>--disable-assert</code><br /></dt>
<dd><p>Disable compiling run-time assertions.  In maintainer
mode, assertion failures are fatal.</p>
</dd>

<dt><code>--disable-assert-messages</code><br /></dt>
<dd><p>Disable compiling run-time assertion failure messages.
In maintainer mode, assertion failures are fatal after the assertion
failure is reported.</p>
</dd>

<dt><code>--enable-debug</code><br /></dt>
<dd><p>Enable debug messages (default not enabled).
Maintainer mode automatically enables this.</p>
</dd>

<dt><code>--enable-digests=LIST</code><br /></dt>
<dd><p>Does nothing - only builtin content digests are available now:
MD5 and SHA1.</p></dd>

<dt><code>--enable-parsers=LIST</code><br /></dt>
<dd><p>Select the list of RDF parsers to be included if the are availble.  The
valid list of RDF parsers is currently only <code>raptor</code> (the default)
since the older repat parser has been removed.  Raptor uses either of
libxml2 (prefered) or expat.  Redland requires the Raptor parser for
other functionality, so it cannot be disabled.
</p></dd>

<dt><code>--with-bdb=</code> <em>ROOT</em> or <code>no</code><br /></dt>
<dd><p>Enable use of the Berkeley DB library installed at
<em>ROOT</em>.  That means <em>ROOT</em><code>/include</code> must
contain the BDB header <code>db.h</code> and <em>ROOT</em><code>/lib</code>
must contain the library <code>libdb.a</code> (or whatever shared library
version/name your system uses).</p>

<p>If the value is <code>no</code>, the BDB backend store is disabled.</p>

<p>Berkeley DB (also known as Sleepycat DB) is distributed and supported by
<a href="http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html">Oracle</a>.
Versions between 2.4 to 5.3 should work.  Version 6 onwards will not
be supported due to the change to the AGPL license, which would
probably force Redland librdf to be AGPL licensed.  Some systems do
not come installed with a working Berkeley DB so on those systems,
Redland will have no persistent storage unless BDB is built
separately and enabled via this option.</p>

<p><b>Note</b>: If you change installed versions of BDB then you will
need to re-configure Redland carefully to let it discover the
features of the newer BDB as follows:</p>
<pre>
  rm -f config.cache
  make clean
  ./configure ... # any configure arguments here
</pre>
<p>(plus you might need to use the
<code>db</code><em>X</em><code>_upgrade</code>
utility to update the BDB database files to the formats supported by
the newer version <em>X</em> - see the BDB documentation to find out
if this is required.)</p>

<p>If the BerkeleyDB is installed in different places from
<em>ROOT</em><code>/lib</code> (library) and
<em>ROOT</em><code>/include</code> (header) or
the library name is something that can't be worked out automatically,
then you can use the next set of options to specify them.</p>

<p>If all of the BDB options are omitted, Redland will do
a best efforts guess to find the newest BDB installation but
this may not work for all configurations.</p>
</dd>

<dt><code>--with-bdb-lib=</code><em>LIBDIR</em><br /></dt>
<dt><code>--with-bdb-include=</code><em>INCDIR</em><br /></dt>
<dt><code>--with-bdb-name=</code><em>NAME</em><br /></dt>
<dd><p>Use Berkeley DB with the installed library in <em>LIBDIR</em>
and the <code>db.h</code> header in <em>INCDIR</em> and
the installed library called <em>NAME</em>
like <code>-l</code><em>NAME</em>.  This is relative to <em>LIBDIR</em>.
All of these options can be omitted and <code>configure</code> will
try to find or guess the values from the system.</p>

<p>For example, to compile redland on OSX with
<a href="http://www.finkproject.org/">fink</a>
might require a configure line something like this:</p>
<pre>
  ./configure --with-bdb-lib=/sw/lib \
              --with-bdb-include=/sw/include/db3
</pre>
<p>The name of the BDB library was correctly discovered for this
configuration, as <code>db-3.3</code>.</p>

<p>If all of the BDB options are omitted, Redland will do
a best efforts guess to find the newest BDB installation but
this may not work for all configurations.</p>

<p>(At present, Redland knows of the default <code>/sw</code> Fink
installation directory and will look there for BDB installs)</p>

</dd>

<dt><code>--with-mysql</code>(<code>=</code><em>CONFIG</em>|<code>yes</code>|<code>no</code>)<br /></dt>

<dd><p>Enable use of the Redland MySQL 3.x, 4.x triple store backend
using <em>CONFIG</em> for the <em>mysql_config</em> program. The
default when either no argument is given, or
<code>--with-mysql</code> alone, is to search for
<em>mysql_config</em> on the search PATH.  With
<code>--with-mysql=no</code>, this store is disabled.</p>

<p>Versions 3.23.58 and 4.0.4 have been tested and work.</p>

</dd>

<dt><code>--with-openssl-digests</code><br /></dt>
<dd><p>Enable the content digests provided by the
<a href="http://www.openssl.org/">OpenSSL</a>
libcrypto library (MD5, SHA1 and RIPEMD160) if the library is
available. configure will automatically enable this unless disabled
by setting this option to <em>no</em>.</p></dd>

<dt><code>--with-postgresql</code>(<code>=</code><em>CONFIG</em>|<code>yes</code>|<code>no</code>)<br /></dt>
<dd><p>Enable use of the Redland PostgreSQL triple store backend
using <em>CONFIG</em> for the <em>pg_config</em> program. The
default when either no argument is given, or
<code>--with-postgresql</code> alone, is to search for
<em>pg_config</em> on the search PATH.  With
<code>--with-postgresql=no</code>, this store is disabled.
</p></dd>

<dt><code>--with-sqlite=</code>(<code>yes</code>|<code>no</code>|<code>2</code>|<code>3</code>)<br /></dt>
<dd><p>Enable use of <a href="http://www.sqlite.org/">SQLite</a>
triple store backend with a particular version V2 or V3,
an automatically chosen one with <code>yes</code> or disable it
(with <code>no</code>).
</p></dd>

<dt><code>--with-threestore</code>(<code>=</code><em>CONFIG</em>|<code>yes</code>|<code>no</code>)<br /></dt>
<dd><p>Enable use of the AKT project
<a href="http://www.aktors.org/technologies/3store/">3store triple store</a>
backend using <em>CONFIG</em>
for the <em>3store-config</em> program. The default when either
no argument is given, or <code>--with-threestore</code> alone, is to search for
the 3store-config on the search PATH.  With
<code>--with-threestore=no</code>, this store is disabled.</p></dd>

<dt><code>--with-xml-parser=NAME</code><br /></dt>
<dd><p>Pick an XML parser to use for Raptor - either <code>libxml</code>
(default) or <code>expat</code>.  If this option is not given,
either will be used, with libxml preferred if both are present.
One of these much be available for Raptor to parse XML syntaxes.</p>

<p>Raptor has been tested with various combinations of these libraries
that are described further in the Raptor
<a href="http://librdf.org/raptor/INSTALL.html">install</a>
documentation.
</p>
</dd>

</dl>


<p><b>WARNING</b> If the Sleepycat/Berkeley DB library is installed
in a non-default directory, when the final linking occurs, the
libraries may not be found at run time.  To fix this you will need to
use a system-specific method of passing this information to the
run-time loader.
On most systems you can set the <code>LD_LIBRARY_PATH</code>
environment variable to include the directory where the
<code>librdf</code> shared library is found. (On OSX this is
<code>DYLD_LIBRARY_PATH</code>).  You can also configure it via a
system wide file - see the <code>ld</code>, <code>ld.so</code>,
or<code>ld.so.1</code> or <code>dyld</code> manual pages for details.
</p>


<h3>2.3 Configuring</h3>

<p>The default configuration will install into /usr/local:
</p>
<pre>
   ./configure
</pre>

<p>To install into the standard Unix / Linux (and also Cygwin) system
directory, use:
</p>
<pre>
   ./configure --prefix=/usr
</pre>

<p>Append to the line any additional options you need like this:
</p>
<pre>
   ./configure --prefix=/usr --with-bdb=/usr/local/berkeleydb
</pre>

<p>If you are having problems with configuring several times when
adding or removing options, you may have to tidy up first with either
of these:</p>
<pre>
   make clean
   rm -f config.cache
</pre>

<h3>2.4 Compiling</h3>

<p>Compile the library and the <tt>rdfproc</tt> utility with:
</p>
<pre>
   make
</pre>
<p>Note: GNU make is probably required which may be called
gmake or gnumake if your system has a different make available too.
</p>


<h2 id="sec-testing">2.5. Testing</h2>

<p>You can build and run the built-in tests for Redland with:</p>
<pre>
    make check
</pre>
<p>which should emit lots of exciting test messages to the screen but
conclude with something like:<br />
  <code>All </code><em>n</em><code> tests passed</code><br />
if everything works correctly.</p>


<p>(If you have got all the required subsidiary development tools,
you can also do <code>make distcheck</code> which does a longer
check that the distribution installation, configuring and building
works.  This does not perform any additional core testing).</p>



<h3 id="sec-install">2.6 Installing the library</h3>

<p>To install the C library (static and shared typically) plus the
interface header (.h) files do:</p>

<pre>
   make install
</pre>




<h2>3. Using the library</h2>

<p>Once the library has been configured and built, there are 
several C example programs that can be used.  They are 
in the <code>examples</code> sub-directory and can be built with:</p>
<pre>
   cd examples

   make EXAMPLE
   # or on cygwin
   make EXAMPLE.exe
</pre>

<p>or to build all of them</p>
<pre>
   make examples
</pre>


<p>If no Berkeley DB was found by configure, some of the examples will fail
since there is no on-disk storage system available.  To change them
to use the in-memory hashes, edit the lines reading something like</p>
<pre>
  storage=librdf_new_storage("hashes",
                             "test", 
                             "hash_type='bdb',dir='.'");
</pre>
<p>to read</p>
<pre>
  storage=librdf_new_storage("hashes", 
                             "test",
                             "hash_type='memory',dir='.'");
</pre>



<h3>3.1 rdfproc</h3>

<p>The <code>rdfproc</code> utility in the utils directory exercises
the majority of the useful parts of the Redland API and can
demonstrate many ways to store, search and manipulate the graph from C.
</p>

<h3>3.2. <a href="example1.c">example1.c</a></h3>

<p><code>example1</code> uses a RDF parser, if you have one available, to
parse a URI of RDF/XML content, store it in multple Berkeley DB
hashes on the disk and run queries against them.  It takes two
arguments, the first the URI of the RDF/XML content (or
<code>file:</code><em>filename</em>) and the second, optional one, is the
name of the RDF parser to use.</p>

<h3>3.3. <a href="example2.c">example2.c</a></h3>

<p><code>example2</code> does not use a RDF parser, but reads from a
simple triple dump format and again stores the data on disk in
multiple Berkeley DB hashes.</p>

<h3>3.4. <a href="example3.c">example3.c</a></h3>

<p><code>example3</code> contains a 10 line main program that creates
an RDF model, a statement, adds it to the model and stores it on
disk.</p>

<h3>3.5. <a href="example4.c">example4.c</a></h3>

<p><code>example4</code> contains an example of how to
serialize an RDF model to a syntax.</p>


<hr />

<p>Copyright (C) 2000-2013 <a href="http://www.dajobe.org/">Dave Beckett</a><br />Copyright (C) 2000-2005 <a href="http://www.bristol.ac.uk/">University of Bristol</a></p>

</body>
</html>
